﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Clandestine
{

    public delegate void MenuSelect(Menu menu); // Fired for ANY item being selected -- to close menu etc.
    public delegate void MenuItemSelect(MenuItem item); // Fired for the item being selected

    public class MenuItem 
    {
        public string Text = string.Empty;
        public TextSprite Sprite;
        public event MenuItemSelect OnSelect;
        public Object Object = new Object();

        public void Select()
        {
            Log.i("Menu: Item {0} selected.", Text);
            if (OnSelect != null)
                OnSelect(this);
        }

        public MenuItem(string text, object o, MenuItemSelect onSelect) : this(text, onSelect)
        {
            this.Object = o;
        }
        public MenuItem(string text, MenuItemSelect onSelect)
        {
            this.Text = text;
            this.OnSelect += onSelect;
        }

        ~MenuItem()
        {
            this.Dispose();
        }

        public void Dispose()
        {
            if (Sprite != null)
                Sprite.Dispose();
        }

        public void RenderSprite(Point pos, Font font, float layer)
        {
            if (Sprite == null) 
                Sprite = font.DrawText(Text);
                Sprite.Position = pos;
                Sprite.Layer = layer;
        }

        public static Point GetPosition(Point origin, Padding pad, int itemNumber, int totalItems, Font font)
        {
            origin.X += pad.Left;
            origin.Y += ((itemNumber) * (font.Height + 3)) + pad.Top;
            return origin;
        }
    }
}
